home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / gblanker36_src.lha / GSource.lha / GSource / Blankers / GoldenSpiral / blank.c next >
Encoding:
C/C++ Source or Header  |  1994-12-20  |  3.3 KB  |  141 lines

  1. /*
  2.  *  Copyright (c) 1994 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10. #include "/includes.h"
  11. #include <math.h>
  12.  
  13. #define AREA_SIZE 100
  14. #define GOLDEN_NUMBER (( sqrt( 5.0 ) - 1.0 )/2.0 )
  15. #define GOLDEN_ANGLE ( 2 * PI * ( 1.0 - GOLDEN_NUMBER ))
  16.  
  17. #include "GoldenSpiral_rev.h"
  18. STATIC const UBYTE VersTag[] = VERSTAG;
  19.  
  20. VOID Defaults( PrefObject *Prefs )
  21. {
  22.     Prefs[0].po_Level = 2;
  23.     Prefs[2].po_ModeID = getTopScreenMode();
  24.     Prefs[2].po_Depth = 4;
  25. }
  26.  
  27. VOID DrawDiamond( struct RastPort *Rast, LONG x, LONG y, LONG r )
  28. {
  29.     AreaMove( Rast, x + r/2, y );
  30.     AreaDraw( Rast, x + r - 1, y + r/2 );
  31.     AreaDraw( Rast, x + r/2, y + r - 1 );
  32.     AreaDraw( Rast, x, y + r/2 );
  33.     AreaEnd( Rast );
  34. }
  35.  
  36. LONG Spiral( struct Screen *Scr )
  37. {
  38.     double Side = (double)min( Scr->Width, Scr->Height ), Radius, Angle = 0.0;
  39.     LONG Color = 0, x, y, Colors = ( 1L << Scr->RastPort.BitMap->Depth ) - 1;
  40.     LONG Size, RetVal, Iter = 0;
  41.     
  42.     for( Radius = 0.05; Radius < 0.5; Radius = Radius + 0.0001 )
  43.     {
  44.         x = ( LONG )( Radius * sin( Angle ) * Side ) + Scr->Width/2;
  45.         y = ( LONG )( Radius * cos( Angle ) * Side ) + Scr->Height/2;
  46. #ifdef LAME_COLORS        
  47.         Color = ( LONG )((( double )Colors * Radius )) * 2.0;
  48. #endif
  49.         SetAPen( &Scr->RastPort, Color );
  50.         Size = ( LONG )( Side / 50.0 * sqrt( Radius ));
  51.         if( x >= Size/2 && y >= Size/2 && x < Scr->Width-Size/2-1 &&
  52.            y < Scr->Height-Size/2-1 )
  53.             DrawDiamond( &Scr->RastPort, x-Size/2, y-Size/2, Size );
  54.         Angle = Angle + GOLDEN_ANGLE;
  55. #ifndef LAME_COLORS
  56.         Color = Color % Colors + 1;
  57. #endif
  58.         
  59.         if(!( Iter++ % 10 )&&(( RetVal = ContinueBlanking()) != OK ))
  60.             break;
  61.     }
  62.  
  63.     return RetVal;
  64. }    
  65.  
  66. LONG Blank( PrefObject *Prefs )
  67. {
  68.     LONG ToFrontCount = 0, Wid, Hei, ExtendPalette, RetVal = OK;
  69.     struct AreaInfo AreaInf;
  70.     struct TmpRas TmpRast;
  71.     Triplet *ColorTable;
  72.     PLANEPTR RasterBuf;
  73.     struct Screen *Scr;
  74.     struct Window *Wnd;
  75.     STRPTR AreaBuf;
  76.     
  77.     ExtendPalette = Prefs[0].po_Level;
  78.     
  79.     Scr = OpenScreenTags( 0L, SA_Depth, Prefs[2].po_Depth, SA_Quiet, TRUE,
  80.                          SA_Overscan, OSCAN_STANDARD, SA_Behind, TRUE,
  81.                          SA_DisplayID, Prefs[2].po_ModeID, TAG_DONE );
  82.     if( Scr )
  83.     {
  84.         Wid = Scr->Width;
  85.         Hei = Scr->Height;
  86.         
  87.         RasterBuf = AllocRaster( Wid, Hei );
  88.         AreaBuf = AllocVec( AREA_SIZE, MEMF_CLEAR );
  89.  
  90.         if( RasterBuf && AreaBuf )
  91.         {
  92.             InitArea( &AreaInf, AreaBuf, AREA_SIZE/5 );
  93.             Scr->RastPort.AreaInfo = &AreaInf;
  94.             InitTmpRas( &TmpRast, RasterBuf, RASSIZE( Wid, Hei ));
  95.             Scr->RastPort.TmpRas = &TmpRast;
  96.             
  97.             ColorTable = RainbowPalette( Scr, 0L, 1L, ExtendPalette );
  98.             SetRast( &( Scr->RastPort ), 0 );
  99.             
  100.             Wnd = BlankMousePointer( Scr );
  101.             ScreenToFront( Scr );
  102.             
  103.             RetVal = Spiral( Scr );
  104.  
  105.             while( RetVal == OK )
  106.             {
  107.                 WaitTOF();
  108.                 
  109.                 if(!( ToFrontCount % ( 10 * ( 5 - ExtendPalette ))))
  110.                     RainbowPalette( Scr, ColorTable, 1L, ExtendPalette );
  111.                 
  112. #ifdef BLAH_SHMINKE
  113.                 if(!( ToFrontCount % 60 ))
  114.                     ScreenToFront( Scr );
  115. #endif
  116.                 
  117.                 if(!( ToFrontCount % 30 ))
  118.                     RetVal = ContinueBlanking();
  119.             }
  120.  
  121.             UnblankMousePointer( Wnd );
  122.             RainbowPalette( 0L, ColorTable, 1L, ExtendPalette );
  123.         }
  124.         else
  125.             RetVal = FAILED;
  126.  
  127.         if( RasterBuf )
  128.             FreeRaster( RasterBuf, Wid, Hei );
  129.  
  130.         if( AreaBuf )
  131.             FreeVec( AreaBuf );
  132.     }
  133.     else
  134.         RetVal = FAILED;
  135.     
  136.     if( Scr )
  137.         CloseScreen( Scr );
  138.     
  139.     return RetVal;
  140. }
  141.